package leetcode.数组;

/**
 * @author: levi
 * @description: https://leetcode.cn/problems/move-zeroes/
 * @date: 2022-9-14 13:26
 * @version: 1.0
 */
public class 移动零_283 {

    public static void main(String[] args) {
        int[] nums = {0,2,4,1,6,0,5,0,0};
        moveZeroes(nums);
        for (int num : nums) {
            System.out.println(num);
        }
    }

    public static void moveZeroes(int[] nums) {
        if(nums == null) return;

        int pre = 0;
        for (int cur = 0; cur < nums.length; cur++) {
            if(nums[cur] != 0){
                nums[pre ++] = nums[cur];
            }
        }

        for (int j = pre; j < nums.length; j++) {
            nums[j] = 0;
        }
    }
}
